﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Init {
    import Engine.Classes.*;
    import flash.events.*;
    import Engine.Events.*;
    import flash.utils.*;

    public class FacebookInit extends SocialNetworkInit {

        protected static const FB_API_KEY:String = "";
        protected static const FB_SECRET:String = "";

        protected var m_facebookUtil:FacebookUtil;
        protected var m_facebookUtilClass:Class = null;

        public function FacebookInit(_arg1:Boolean, _arg2:Class=null){
            if (_arg2 == null){
                _arg2 = FacebookUtil;
            };
            this.m_facebookUtilClass = _arg2;
            super(_arg1);
        }
        override public function execute():void{
            var _local1:Timer;
            if (m_skipSN){
                super.execute();
            } else {
                GlobalEngine.socialNetwork = (GlobalEngine.socialNetwork = (this.m_facebookUtil = new this.m_facebookUtilClass(this.getApiKey(), this.getSecret())));
                if (this.m_facebookUtil.needsLogin){
                    this.addEventListener(MouseEvent.CLICK, this.onLoginClick);
                    this.m_facebookUtil.addEventListener(SocialNetworkEvent.LOGIN_COMPLETE, this.onLoginComplete);
                    _local1 = new Timer(4000);
                    _local1.addEventListener(TimerEvent.TIMER, this.onLoginClick);
                    _local1.start();
                } else {
                    this.onLoginComplete(null);
                };
            };
        }
        private function onLoginComplete(_arg1:Event):void{
            this.m_facebookUtil.removeEventListener(SocialNetworkEvent.LOGIN_COMPLETE, this.onLoginComplete);
            this.m_facebookUtil.addEventListener(SocialNetworkEvent.GET_USER_COMPLETE, this.onGetUserComplete);
            this.m_facebookUtil.getUser();
        }
        private function onGetUserComplete(_arg1:SocialNetworkEvent):void{
            this.m_facebookUtil.removeEventListener(SocialNetworkEvent.GET_USER_COMPLETE, this.onGetUserComplete);
            dispatchEvent(new Event(Event.COMPLETE));
            this.m_facebookUtil.addEventListener(SocialNetworkEvent.GET_FRIENDS_COMPLETE, this.onGetFriendsComplete);
            this.m_facebookUtil.getFriendList();
        }
        private function onGetFriendsComplete(_arg1:SocialNetworkEvent):void{
            this.m_facebookUtil.removeEventListener(SocialNetworkEvent.GET_FRIENDS_COMPLETE, this.onGetFriendsComplete);
            this.m_facebookUtil.addEventListener(SocialNetworkEvent.GET_APP_FRIENDS_COMPLETE, this.onGetAppFriendsComplete);
            this.m_facebookUtil.getAppFriends();
        }
        private function onGetAppFriendsComplete(_arg1:SocialNetworkEvent):void{
            this.m_facebookUtil.removeEventListener(SocialNetworkEvent.GET_APP_FRIENDS_COMPLETE, this.onGetAppFriendsComplete);
            this.setupOnFriendsComplete();
        }
        protected function setupOnFriendsComplete():void{
        }
        private function onLoginClick(_arg1:Event=null):void{
            this.m_facebookUtil.validateLogin();
        }
        protected function getApiKey():String{
            return ((GlobalEngine.getFlashVar("fb_sig_api_key") as String));
        }
        protected function getSecret():String{
            return ((GlobalEngine.getFlashVar("fb_sig_api_secret") as String));
        }

    }
}//package Init 
